<?php
require_once '../application/modules/admin/models/Cliente.php';

class Admin_ClienteController extends Zend_Controller_Action
{

    public function init()
    {
    	if(!Zend_Auth::getInstance()->hasIdentity()){
			$this->_redirect('admin/login');
		}
    }

	public  function indexAction()
   	{
      	$model = new Application_Modules_Admin_Model_Cliente();
      	$dados = $model->select();
 
      	$this->view->assign("dados", $dados);
   	}
 
   	public function showAction()
   	{
      	$model = new Application_Modules_Admin_Model_Cliente();
      	$cliente = $model->find($this->_getParam('id'));
 
		$this->view->assign("cliente", $cliente);
   	}
 
   	public function newAction()
   	{

   	}
 
   	public function createAction()
   	{
		try{
      		$model = new Application_Modules_Admin_Model_Cliente();
   			$model->insert($this->_getAllParams());  				 		
   		}catch (Exception $e){
			echo '{"status":' . $e->getMessage() . '}';
			exit;
		}
		echo '{"status":true}';	
		exit;
   	}

   	public  function editAction()
   	{
   		$model = new Application_Modules_Admin_Model_Cliente();
   		$cliente = $model->find($this->_getParam('id'));
   	
   		$this->view->assign("cliente", $cliente);
   	}
   	
   	public function updateAction()
   	{
		try{
      		$model = new Application_Modules_Admin_Model_Cliente();
   			$model->update($this->_getAllParams());     				 		
   		}catch (Exception $e){
			echo '{"status":' . $e->getMessage() . '}';
			exit;
		}
		echo '{"status":true}';	
		exit;
   	}
   	
   	public function destroyAction()
   	{
   		$model = new Application_Modules_Admin_Model_Cliente();
   		$model->delete($this->_getParam('id'));
   	
   		$this->_redirect('admin/cliente/index');
   	}
}



